<!--
 * @Author: typ
 * @Date: 2025-01-15 10:15:08
 * @LastEditors: typ
 * @LastEditTime: 2025-02-14 15:19:14
 * @FilePath: /720Manage-vite/src/views/model3D/index.vue
 * @Description: 
-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="模型名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入模型名称" clearable style="width: 200px"
          @keyup.enter="handleQuery" @change="handleQuery" />
      </el-form-item>
      <el-form-item label="模型类型" prop="type">
        <el-select @change="handleQuery" v-model="queryParams.type" placeholder="请选择模型类型" clearable
          style="width: 200px">
          <el-option v-for="item in sys_model_type" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        <!-- <el-button type="warning" icon="Upload" @click="handleImport">导入模型</el-button> -->
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="tableList" :default-sort="{ prop: 'createTime', order: 'descending' }">
      <el-table-column label="序号" align="center" type="index" width="90" />
      <el-table-column label="模型名称" align="center" prop="name" />
      <el-table-column label="模型类型" align="center" prop="type">
        <template #default="scope">
          <dict-tag :options="sys_model_type" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="模型来源" align="center" prop="dataFrom" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <el-tag v-if="scope.row.status === '1'" type="success">已发布</el-tag>
          <el-tag v-else type="danger">未发布</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" width="160" />
      <el-table-column label="创建时间" align="center" prop="createTime" sortable width="160" />
      <el-table-column label="操作" width="160" align="center" class-name="small-padding fixed-width"
        style="display: flex; align-items: center; justify-content: center">
        <template #default="scope">
          <!-- <el-button link type="primary" icon="Edit" @click="handleEdit(scope.row)">编辑</el-button> -->
          <el-button link type="primary" @click="handleView(scope.row)">预览</el-button>
          <el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
          <el-button v-if="scope.row.status === '0'" link type="primary"
            @click="handlePublish(scope.row)">发布</el-button>
          <el-button v-else link type="primary" @click="handleCanceld(scope.row)">取消发布</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { getModelList, CanceldPublishModel, publishModel, delModel } from '@/api/model'
import { useRouter } from 'vue-router'
const router = useRouter();
const { proxy } = getCurrentInstance()
const { sys_model_type } = proxy.useDict("sys_model_type");
const queryParams = ref({
  name: '',
  pageNum: 1,
  pageSize: 10
})
let total = ref(0)
let loading = ref(false)
let tableList = ref([])

onMounted(() => {
  getList()
})
// 获取模型列表
const getList = () => {
  getModelList(queryParams.value).then(res => {
    tableList.value = res.rows
    total.value = res.total
  })
}
// 查询
const handleQuery = () => {
  getList()
}

// 重置查询条件
const resetQuery = () => {
  queryParams.value = {
    name: ''
  }
}
// 编辑
const handleEdit = (row) => {
  router.push({ path: '/editModel', query: { id: row.id } })
}

// 模型预览
const handleView = (row) => {
  if (row.type === '1') {
    window.open('/modelView?id=' + row.taskId, '_blank');
  } else {
    window.open('/b3dmPreview?id=' + row.taskId, '_blank');
  }
}
// 删除
const handleDelete = (row) => {
  proxy.$modal.confirm('是否确认删除模型名称为"' + row.name + '"的数据项？').then(function () {
    return delModel(row.id);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => { });
}
// 发布
const handlePublish = (row) => {
  proxy.$modal.confirm('是否确认发布名称为"' + row.name + '"的数据？').then(function () {
    return publishModel(row.id);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("发布成功");
  }).catch(() => { });
}
// 取消发布
const handleCanceld = (row) => {
  proxy.$modal.confirm('是否确认取消发布名称为"' + row.name + '"的数据？').then(function () {
    return CanceldPublishModel(row.id);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("取消发布成功");
  }).catch(() => { });
}
</script>

<style lang="scss" scoped></style>